package com.result.demo.global.result;

import com.result.demo.global.enums.ResultCode;
import lombok.Data;
import java.io.Serializable;


/**
 * @author chao.z
 */
@Data
public class Result implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer code;

    private String message;

    private Object data;



    public static Result success(){
       Result result = new Result();
       result.setCode(ResultCode.SUCCESS.getCode());
       result.setMessage(ResultCode.SUCCESS.getMessage());
        return result;
    }
    public static Result success(Object data){
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }
    public static Result failure(ResultCode resultCode){
        Result result = new Result();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMessage());
        return result;
    }

    public static Result failure(Integer resultCode, String message){
        Result result = new Result();
        result.setCode(resultCode);
        result.setMessage(message);
        return result;
    }

    public static Result error(){
        Result result = new Result();
        result.setCode(ResultCode.SYSTEM_ERROR.getCode());
        result.setMessage(ResultCode.SYSTEM_ERROR.getMessage());
        return result;
    }
    public static Result error(Integer resultCode,String message){
        Result result = new Result();
        result.setCode(resultCode);
        result.setMessage(message);
        return result;
    }



}
